Skip to content

change the type of the argument of drop_in_place lang item to &mut _#154327

Merged
rust-bors[bot] merged 8 commits intorust-lang:mainfrom
WaffleLapkin:drop_in_place_ref
May 7, 2026
Merged

change the type of the argument of drop_in_place lang item to &mut _#154327
rust-bors[bot] merged 8 commits intorust-lang:mainfrom
WaffleLapkin:drop_in_place_ref

Conversation

@WaffleLapkin
Copy link
Copy Markdown
Member

@WaffleLapkin WaffleLapkin commented Mar 24, 2026

View all comments

We used to special case core::ptr::drop_in_place when computing LLVM argument attributes with this hack:

let drop_target_pointee_info = drop_target_pointee.and_then(|pointee| {
assert_eq!(pointee, layout.ty.builtin_deref(true).unwrap());
assert_eq!(offset, Size::ZERO);
// The argument to `drop_in_place` is semantically equivalent to a mutable reference.
let mutref = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, pointee);
let layout = cx.layout_of(mutref).unwrap();
layout.pointee_info_at(&cx, offset)
});
if let Some(pointee) = drop_target_pointee_info.or_else(|| layout.pointee_info_at(&cx, offset))

This is because even though drop_in_place takes a *mut T it is semantically a &mut T (remember how &mut Self is passed to Drop::drop). This is apparently relevant for perf.

This PR replaces this hack with a simpler solution -- it makes drop_in_place a thin wrapper around newly added core::ptr::drop_glue, which is the actual lang item and takes a &mut T:

pub const unsafe fn drop_in_place<T: PointeeSized>(to_drop: *mut T)
where
T: [const] Destruct,
{
// Due to historic reasons, `drop_in_place` takes a pointer rather than a reference,
// which results in worse codegen since we don't apply noalias/dereferenceable llvm
// attributes to pointer arguments. To workaround this without breaking public
// interface, `drop_in_place` calls the lang item, rather than being one directly.
// SAFETY:
// - compiler glue has the same safety requirements as this function
// - the pointer must be valid as per the safety requirement of this function
unsafe { drop_glue(&mut *to_drop) }
}
/// Helper function for `drop_in_place`.
#[lang = "drop_glue"]
const unsafe fn drop_glue<T: PointeeSized>(_: &mut T)
where
T: [const] Destruct,
{
// Code here does not matter - this is replaced by the
// real drop glue by the compiler.
}


The rest of the PR is blessing tests and cleaning up things which are not necessary after this change.

One thing that is a bit awkward is that now that drop_glue is the actual lang item, a lot of the comments referring to drop_in_place are outdated. Should I try fixing that?

I've also changed async_drop_in_place to take a &mut T, and it simplified the code handling it a bit. (since it's unstable we don't need to introduce a wrapper)


cc @RalfJung
Closes #154274

@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 24, 2026
@RalfJung
Copy link
Copy Markdown
Member

Oh wow I hadn't expected my wish to be fulfilled before I could even finish my PR that motivated me to express the wish in the first place. :-) ❤️

Comment thread library/core/src/ptr/mod.rs Outdated
@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_const_eval/src/interpret/place.rs
Comment thread library/core/src/ptr/mod.rs Outdated
@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_const_eval/src/interpret/place.rs
@WaffleLapkin WaffleLapkin force-pushed the drop_in_place_ref branch 2 times, most recently from 794fcf5 to ea0c913 Compare April 5, 2026 18:31
@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. labels Apr 5, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_const_eval/src/interpret/place.rs Outdated
@RalfJung
Copy link
Copy Markdown
Member

RalfJung commented Apr 6, 2026

I like the interpreter changes and renames. Not sure what the status of the rest of the PR is, but if you submit just those as a separate PR I'll r+.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 6, 2026
…s, r=RalfJung

Slightly refactor mplace<->ptr conversions

split off of rust-lang#154327

r? RalfJung
@WaffleLapkin
Copy link
Copy Markdown
Member Author

@bors try jobs=test-various

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 6, 2026
change the type of the argument of `drop_in_place` lang item to `&mut _`


try-job: test-various
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 6, 2026

☀️ Try build successful (CI)
Build commit: 006163a (006163a6720d54bc0cb68c169754981f750a7f87, parent: e95e73209faf6ead2bc5c7636e45e589a751b79b)

@scottmcm
Copy link
Copy Markdown
Member

scottmcm commented May 6, 2026

@bors r=RalfJung,scottmcm,saethlin

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 6, 2026

📌 Commit 94e4ddf has been approved by RalfJung,scottmcm,saethlin

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 6, 2026
@rust-bors

This comment has been minimized.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI, Post merge analysis
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

3 similar comments
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI, Post merge analysis
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI, Post merge analysis
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI, Post merge analysis
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (4ddd453): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.4% [0.4%, 0.4%] 1
Improvements ✅
(primary)
-0.1% [-0.1%, -0.1%] 1
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 2
All ❌✅ (primary) -0.1% [-0.1%, -0.1%] 1

Max RSS (memory usage)

Results (primary -1.2%, secondary 3.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.1% [1.5%, 2.7%] 2
Regressions ❌
(secondary)
4.4% [1.2%, 7.9%] 4
Improvements ✅
(primary)
-3.4% [-4.2%, -2.1%] 3
Improvements ✅
(secondary)
-2.5% [-2.5%, -2.5%] 1
All ❌✅ (primary) -1.2% [-4.2%, 2.7%] 5

Cycles

Results (primary 7.3%, secondary 0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
7.3% [5.8%, 8.8%] 2
Regressions ❌
(secondary)
0.8% [0.4%, 2.3%] 10
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.3% [-3.3%, -3.3%] 1
All ❌✅ (primary) 7.3% [5.8%, 8.8%] 2

Binary size

Results (primary -0.1%, secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.2%] 2
Regressions ❌
(secondary)
0.3% [0.2%, 0.4%] 2
Improvements ✅
(primary)
-0.2% [-0.3%, -0.0%] 4
Improvements ✅
(secondary)
-0.2% [-1.9%, -0.0%] 19
All ❌✅ (primary) -0.1% [-0.3%, 0.2%] 6

Bootstrap: 500.816s -> 499.861s (-0.19%)
Artifact size: 395.23 MiB -> 394.98 MiB (-0.06%)

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI, Post merge analysis
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

5 similar comments
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI, Post merge analysis
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI, Post merge analysis
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI, Post merge analysis
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI, Post merge analysis
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

☀️ Test successful - CI, Post merge analysis
Approved by: RalfJung,scottmcm,saethlin
Duration: 3h 12m 34s
Pushing 4ddd453 to main...

@WaffleLapkin
Copy link
Copy Markdown
Member Author

@Kobzol uhhhhh... it's bors supposed to do this?

@bjorn3
Copy link
Copy Markdown
Member

bjorn3 commented May 7, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` merged-by-bors This PR was explicitly merged by bors. PG-exploit-mitigations Project group: Exploit mitigations T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

internal drop_in_place shim should take &mut arguments

9 participants